//https://juejin.cn/book/6844733763675488269/section/6844733763759374350

var getTwoBit = function(n){
    return (n > 9 ? '' : '0') + n
}
//格式化日期或获取今天完整日期
var getTime = function(value,format,split='-'){
    if(value){
        var date = new Date(value);
    }else{
        var date = new Date();
    }
    var y = date.getFullYear();
    var m = getTwoBit(date.getMonth() + 1);
    var d = getTwoBit(date.getDate());
    var h = getTwoBit(date.getHours());
    var min = getTwoBit(date.getMinutes());
    var s = getTwoBit(date.getSeconds());
    var partOne = [y, m, d].join(split);
    var partTwo = [h,min,s].join(':');
    if(format == 'ymd'){
        return partOne
    }else if(format == 'hms'){
        return partTwo;
    }else{
        return partOne + " " + partTwo;
    }
}
var getBeforeDay = function(val,format,split){
    var date = new Date();
    date.setTime(date.getTime() + 3600 * 1000 * 24 * parseInt(val));
    var beforeDay =  getTime(date,format,split);
    return beforeDay;
}
var formatWordTime = function(){
    let nowTime = getTime();
    let beforeTime =  getBeforeDay(-1);
    //当前时间
    let nowTimeSplit = nowTime.split(" ");
    let nowTimeOne = nowTimeSplit[0].split("-");
    let nowTimeTwo = nowTimeSplit[1].split(":");
    //前一天
    let beforeTimeSplit = beforeTime.split(" ");
    let beforeTimeOne = beforeTimeSplit[0].split("-");
    let beforeTimeTwo = beforeTimeSplit[1].split(":");
    let obj = {
        nowTime:nowTimeOne[1] + '月' + nowTimeOne[2] + '日' + nowTimeTwo[0] + '时',
        beforeTime:beforeTimeOne[1] + '月' + beforeTimeOne[2] + '日' + beforeTimeTwo[0] + '时',
    }
    return obj;
}
formatTime();